package oa.hleast.xswl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import oa.hleast.xswl.mapper.ISysRouteTitleMapper;
import oa.hleast.xswl.pojo.domain.SysRouteTitle;
import oa.hleast.xswl.service.ISysRouteTitleService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional
@AllArgsConstructor
public class SysRouteTitleServiceImpl extends ServiceImpl<ISysRouteTitleMapper, SysRouteTitle> implements ISysRouteTitleService {
    @Override
    public String getTitleByRoute(String route) {
        // 后面加缓存优化

        List<SysRouteTitle> list = this.list(new LambdaQueryWrapper<SysRouteTitle>().eq(SysRouteTitle::getRoute, route).last("limit 1"));
        if (list.size() == 1) {
            log.info(" 从数据库获取 title ，route = {}", route);
            return list.get(0).getTitle();
        }

        log.info(" 从数据库获取 title ，没有相应的映射");
        return "未知";
    }
}
